package org.sportspace.common.services

import org.sportspace.base.domain.TablePayPolicy
import org.sportspace.base.domain.SportOrder
import org.sportspace.base.domain.PayPolicy

class TableOrderService {

    /**
     * 创建订单
     */

    public Map createOrder(Map params){
        return null;
    }

    /**
     * 查询订单
     */
    public Map queryOrder(Map params){
        return null;
    }

    /**
     * 查询一个场地下的订单
     * @param params
     * @return
     */
    public Map queryOrderByTable(Map params){

        List<TablePayPolicy> payPolicies = TablePayPolicy.withCriteria{
            eq("sportTable",params.sportTable);
        };

        List<SportOrder> sportOrderList = [];
        SportOrder.list().each {SportOrder sportOrder->
            sportOrder.payPolicies.each {PayPolicy payPolicy->
                if(payPolicy instanceof TablePayPolicy){
                    if(payPolicy in payPolicies){
                        sportOrderList.add(sportOrder);
                    }
                }
            }
        }

        return [tableOrders:sportOrderList];
    }

    /**
     * 处理订单,进行支付
     */
    public Map dealWithOrder(Map params){
        return null;
    }

}
